<?php
/**
 * Geneone: Content Management Framework
 * Objects: Guest Object Captcha
 *
 * http://geneone.neondragon.net/
 *
 * @package Geneone
 * @author Khlo
 * @version 1.0
 * @copyright 2004-2006 Geneone Development Team
 */
 
class Gene_Special_Captcha {
	/**
	 * Default Action
	 */
	function main() {
		$user =& Gene::getUser();
		
		$id = md5(Gene_Request::getString("id", GENE_REQUEST_GET));
		
		if (Gene::getSetting("object_guest_captcha") && !$user->getUserId()) {
			require_once ("Text/CAPTCHA.php");
			
			$options = array(
				"font_size" => 24,
				"font_path" => GENE_RESOURCES_DIR."fonts/",
				"font_file" => "vera.ttf",
			);
			
			$c = Text_CAPTCHA::factory('Image');
			$retval = $c->init(200, 80, null, $options);
			if (PEAR::isError($retval)) {
			    die ('Error generating CAPTCHA!');
			}
			
			$_SESSION['captcha_object'][$id] = $c->getPhrase();
			
			// Get CAPTCHA image (as PNG)
			$png = $c->getCAPTCHAAsPNG();
			if (PEAR::isError($png)) {
			    die('Error generating CAPTCHA!');
			}
			
			header ("Content-Type: image/png");
			echo $png;
		}
			
		exit();
	}
}

?>